A good answer might be:

    degrees  = Double.parseDouble( charData  ) ;
    
    // calculate its cosine
    double result = Math.cos( Math.toRadians(degrees) );

Function Results as Arguments

You may have noticed that in the answer one function is nested inside another

double result = Math.cos( Math.toRadians(degrees) );

This is perfectly fine, and is a reasonable way to write the code. As long as the inner function returns a value that is correct for the outer function this works fine. In fact, we could combine this line with the line containing the println():

// calculate its cosine and print the result
System.out.println("cosine: " + Math.cos(  Math.toRadians(degrees) ) );

QUESTION 19:

Which page in this chapter is your favorite?